package org.matchit.converter.collection;

import java.util.Map;
import java.util.Map.Entry;

import org.springframework.core.convert.converter.Converter;

/**
 * Convert a map entry into just the key.
 * 
 * @author Jeroen van Schagen
 * @since 20-03-2011
 * 
 * @param <T> type of entry key
 */
public class EntryToKeyConverter<T> implements Converter<Map.Entry<T, ?>, T> {

    /**
     * Construct a new {@link EntryToKeyConverter}. 
     * @param <T> type of entry key
     * @return new converter instance
     */
    public static <T> EntryToKeyConverter<T> key() {
        return new EntryToKeyConverter<T>();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public T convert(Entry<T, ?> source) {
        return source.getKey();
    }

}
